package MainComponent;
import java.io.FileNotFoundException;

import ui.UI;
import dataobj.ConfigTO;

/***
 * Start point of the program
 */
public class MainFunction {
	
	/***
	 * Start Point
	 * @param args	the arguments
	 * @throws FileNotFoundException	if the file cannot find
	 */
	public static void main(String[] args) throws FileNotFoundException{
		ConfigTO config = new ConfigTO();
		UI ui = new UI();
		config.setFilePath(UI.getFilePath());
		
		boolean correctUniversity = false;
		do{
			correctUniversity = getUniversity(config, new UI());
		}while (!correctUniversity);
		createTimetable(ui, new TimetableCreator(config));
	}

	/***
	 * Return whether the correct university name is got.
	 * @param config	the config
	 * @param ui	the user interface
	 * @return		if the university exists
	 */
	private static boolean getUniversity(ConfigTO config, UI ui) {
		if(!config.setUniversity(ui.getUniversity())){
			ui.showMessage("No such univeristy exists, please try again");
			return false;
		}else
			return true;
	}
	
	/***
	 * Return whether the timetable created successfully.
	 * @param ui	the user interface
	 * @param tc	the timetable creator
	 * @return		if the timetable created successfully
	 */
	private static boolean createTimetable(UI ui, TimetableCreator tc){
		if(tc.createTimeTable()){
			ui.showSuccessMessage();
			return true;
		}else{
			ui.showFailMessage();
			return false;
		}
	}
	
	
}
